Repository navigation
fix(chat): deregister sessions via cleanup middleware instead of p.Wait() (#4515) - #8348
Merged
Merged
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 56 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This was referenced Nov 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4515. Supersedes PR #4521.
Problem (verified against the pinned sources)
ProgramHandlerspawnedgo func() { p.Wait(); a.remove(p) }(). In the pinned bubbletea v0.25.0,Program.finishedis created insideRun()(p.finished = make(chan struct{}, 1)), and wish's bubbletea middleware callsp.Run()only after the handler returns — so the earlyWait()reads a nil channel: it can block forever (and raceRun's assignment), leaking the registry entry and its broadcast traffic.Why not PR #4521's approach
PR #4521 deregistered on
s.Context(). Its Codex P2 is correct, verified in the pinned charmbracelet/ssh source: the session context is created once per connection (newContextin server.go), so on a multiplexed connection (ControlPersist / multiple channels) an ended session's program and watcher survive until the whole connection closes.Fix
ProgramHandlernow binds the program to its session (registerSession) and spawns no waiter.sessionCleanupMiddleware, listed after the bubbletea middleware inwish.WithMiddleware(wish composes outside-in from the end of the list), deregisters the session's program after the inner handler chain returns — which is afterp.Run()has finished and the program was killed. Removal is tied to this session's completion: a closed session on a still-live connection is pruned, other sessions on the same connection are untouched.remove()also drops any session binding, so the full-queue prune path cannot leave a stale binding.Tests (oracle: registry contents before/after a session lifecycle)
New
pkgs/chat/session_cleanup_test.go:TestSessionCleanupDeregistersOnHandlerReturn— registered while the handler runs, gone after it returns.TestSessionCleanupLeavesOtherSessions— ending one session leaves a second session's program registered (the PR fix(chat): deregister sessions on session end instead of p.Wait() (#4515) #4521 Codex scenario); unknown-session deregistration is a no-op.TestRemoveDropsSessionBinding— the prune path leaves no binding.go test ./...in pkgs/chat passes, and the three new tests pass under-race. Note:go test -race ./...fails in the pre-existingTestEnterOnEmptyInputBroadcastsNothing(a race inside bubbletea'sNewProgram/handleResize) — reproduced identically on clean main (bd9cbc1) without this change; not introduced here.Links: task 14746 · issue #4515 · superseded PR #4521 · batch issue #7297
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.